<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">

<head>
    <th:block th:include="common/common_head :: commonHeader('供应商银行信息')"/>
    <link th:href="@{/static/css/plugins/cropper/cropper.min.css}" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <form class="form-horizontal" method="post" id="inquiryQuotationFrom">
        <div class="row">
            <div class="form-group">
                <div class="col-sm-8" style="margin-left: 16px">
                    <input class="btn btn-primary" type="button" onclick="save()" value="保存">
                    <button class="btn btn-primary" type="button" onclick="Dialog.closeFrame(window.name)">取 消</button>
                </div>
            </div>
            <div class="form-group">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <div class="form-group">
                            <label class="col-xs-1 control-label">汇总号</label>
                            <div class="col-xs-3">
                                <input type="hidden" name="quotationId"
                                       th:value="${inquiryQuotationEntity.quotationId}">
                                <input name="inquiryTotalCode" th:value="${inquiryQuotationEntity.inquiryTotalCode}"
                                       readonly="readonly" type="text" class="form-control">
                            </div>
                            <label class="col-xs-1 control-label">行号</label>
                            <div class="col-xs-3">
                                <input name="inquiryItemCode" th:value="${inquiryQuotationEntity.inquiryItemCode}"
                                       readonly="readonly" type="text" class="form-control">
                            </div>
                            <label class="col-xs-1 control-label">询报价单号</label>
                            <div class="col-xs-3">
                                <input name="inquiryCode" th:value="${inquiryQuotationEntity.inquiryCode}"
                                       readonly="readonly" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">数量</label>
                            <div class="col-sm-3">
                                <input id="purchaseCnt" name="purchaseCnt"
                                       th:value="${inquiryQuotationEntity.purchaseCnt}" readonly="readonly" type="text"
                                       class="form-control">
                            </div>
                            <label class="col-sm-1 control-label">物料编码</label>
                            <div class="col-sm-3">
                                <input name="materialCode" th:value="${inquiryQuotationEntity.materialCode}"
                                       readonly="readonly" type="text" class="form-control">
                            </div>
                            <label class="col-sm-1 control-label">物料描述</label>
                            <div class="col-sm-3">
                                <input name="materialDesc" th:value="${inquiryQuotationEntity.materialDesc}"
                                       readonly="readonly" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">供应商编码</label>
                            <div class="col-sm-3">
                                <input name="vendorCode" th:value="${inquiryQuotationEntity.vendorCode}" type="text"
                                       class="form-control" readonly="readonly">
                            </div>

                            <label class="col-sm-1 control-label">供应商名称</label>
                            <div class="col-sm-3">
                                <input name="vendorName" th:value="${inquiryQuotationEntity.vendorName}" type="text"
                                       class="form-control" readonly="readonly">
                            </div>
                            <label class="col-sm-1 control-label">订单单位</label>
                            <div class="col-sm-3">
                                <input name="poPriceUnit" th:value="${inquiryQuotationEntity.poUnit}" type="text"
                                       class="form-control" readonly="readonly">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">含税价</label>
                            <div class="col-sm-3">
                                <input id="price" name="price" type="number" class="form-control">
                            </div>

                            <label class="col-sm-1 control-label">最小起订量</label>
                            <div class="col-sm-3">
                                <input id="priceUnit" name="priceUnit" type="text" class="form-control">
                            </div>
                            <label class="col-sm-1 control-label">税码</label>
                            <div class="col-sm-3">
                                <select class="form-control" id="taxCode" name="taxCode" sysDict="SDM" emptyFirst="true"
                                        th:value="${inquiryQuotationEntity.taxCode}"></select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">回复交期</label>
                            <div class="col-sm-3">
                                <input id="replyDeliveryDate" name="replyDeliveryDate" type="text" class="form-control"
                                       autocomplete="off">
                            </div>
                            <label class="col-sm-1 control-label">总价</label>
                            <div class="col-sm-3">
                                <input id="totalPrice" name="totalPrice" type="text" class="form-control"
                                       readonly="readonly">
                            </div>
                            <label class="col-sm-1 control-label">备注</label>
                            <div class="col-sm-3">
                                <input id="remark" name="remark" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">工厂</label>
                            <div class="col-sm-3">
                                <input class="form-control" id="werks" name="werks" th:value="${inquiryQuotationEntity.werks}" readonly>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<!--引入公共js-->
<div th:include="common/onload_js :: onloadJS"></div>
<!-- Chosen -->
<script th:src="@{/static/js/plugins/chosen/chosen.jquery.js}"></script>

<script type="text/javascript">
    //2019-07-09 只能选当天之后的日期
    function minDate() {
        var now = new Date();
        return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate();
    }

    $(function () {
        // 初始化时间插件
        laydate.render({
            elem: '#replyDeliveryDate',
            min: minDate()
        });
        initDictDataSel();//初始化所有字典数据
        //设置税码默认值
        var taxCode = $("#taxCode");
        var taxCodeVal = taxCode.attr('value');
        if (taxCodeVal) {
            var options = taxCode.children();
            for (var i in options) {
                if (taxCodeVal == options[i].value) {
                    options[i].selected = 'selected';
                    break;
                }
            }
        }
    });
    //总价的计算
    document.getElementById("purchaseCnt").onkeyup = calculate;
    document.getElementById("price").onkeyup = calculate;

    function calculate() {
        var price = new Number(document.getElementById("price").value);
        var num = new Number(document.getElementById("purchaseCnt").value);
        if (!isNaN(price) && !isNaN(num)) {
            //乘1000是防止价格小数位直接乘 出现精度问题
            document.getElementById("totalPrice").value = price * 1000 * num / 1000;
        } else {
            document.getElementById("totalPrice").value = "";
        }
    }

    //报价
    function save() {
        var price = $("#price").val();
        var replyDeliveryDate = $("#replyDeliveryDate").val();
        var priceUnit = $("#priceUnit").val();
        if (price == null || price.trim() == '' || price == 0) {
            Dialog.errorMsg("请填写含税价！");
            return;
        }
        if (replyDeliveryDate == null || replyDeliveryDate.trim() == '') {
            Dialog.errorMsg("请填写回复交期！");
            return;
        }

        if (priceUnit == null || priceUnit.trim() == '') {
            Dialog.errorMsg("请填写最小起订量！");
            return;
        }

        if ($("#inquiryQuotationFrom").valid()) {
            Page.ajaxPOST(ctxPath + "/inquiryQuotation/update", $('#inquiryQuotationFrom').serialize(), function (res) {
                Dialog.msg("报价单提交成功!", function () {
                    parent.refresh();
                    Dialog.closeFrame(window.name);
                });
            });
        }
    }
</script>

</body>
</html>
